Skip to content

Conversation

@felixweinberger
Copy link
Contributor

Port of #1994 (v1.x) to main.

Motivation and Context

Sessions created via StreamableHTTPSessionManager persist indefinitely in _server_instances even after the client disconnects, leaking memory over time (issue #1283).

The session_idle_timeout parameter automatically terminates and removes sessions that receive no HTTP requests for the configured duration. Each session manages its own lifetime via an anyio CancelScope deadline — no background reaper task needed. Incoming requests push the deadline forward to keep active sessions alive.

How Has This Been Tested?

11 dedicated tests covering: idle reaping, activity reset, multi-session independence, validation, terminate idempotency, lifecycle, and end-to-end behavior. Existing manager tests continue to pass.

Breaking Changes

None — new optional parameter with default None.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Sessions created via StreamableHTTPSessionManager persist indefinitely
in _server_instances even after the client disconnects, leaking memory
over time.

Add a session_idle_timeout parameter that automatically terminates and
removes sessions that receive no HTTP requests for the configured
duration. Each session manages its own lifetime via an anyio CancelScope
deadline — no background reaper task needed. Incoming requests push the
deadline forward to keep active sessions alive.

Github-Issue: #1283
@felixweinberger felixweinberger force-pushed the fweinberger/idle-timeout-termination-main branch from c8e7443 to 84ac697 Compare February 9, 2026 17:13
@claude
Copy link

claude bot commented Feb 9, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

1 similar comment
@claude
Copy link

claude bot commented Feb 9, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant